import request from '@/config/axios'

const baseURL = '/division'

const skuBaseURL = '/sku/division'

export type Receiver = {
  id: string
  receiverAlias: string
}
export type SkuReceiver = {
  skuId: string
  mchDivisionReceiverId: string //分账账号id
  divisionModel: number //分账模型，1：金额，2：百分比
  divisionProfit?: number //分账比例 最高0.3
  divisionAmount?: number //分账金额，单位：分,最高10000
}

export type ReturnReceiver = {
  id: string
  receiverAlias: string
  skuId: string
  mchDivisionReceiverId: string //分账账号id
  divisionModel: number //分账模型，1：金额，2：百分比
  divisionProfit: number | null //分账比例 最高0.3
  divisionAmount: number | null //分账金额，单位：分,最高10000
}

// 设置分帐
export type SetUpProrate = {
  mode: string
  value: number
  type: string
  account: string
  delay: number
}

// 获取已经绑定的分账账户信息
// accType:分账接收账号类型: 0-个人(对私) 1-商户(对公)
export const getListReceiver = (accType: number) =>
  request.post<Receiver[]>({
    url: `${baseURL}/list-receiver`,
    data: { accType }
  })

// 添加sku分账规则
export const createReceiver = (data: SkuReceiver[]) =>
  request.post<boolean>({
    url: `${skuBaseURL}/batch-create`,
    data
  })

// 根据sku id获取分账信息 receiverAlias 接收者账号别名
export const getBySkuId = (skuId: string) =>
  request.get<ReturnReceiver[]>({
    url: `${skuBaseURL}/get-by-sku-id`,
    params: { skuId }
  })
